#include <stdio.h>
#include <limits.h>

int uadd_ok(unsigned x, unsigned y);

int main() {
    /* 无符号加法是否溢出 */
    printf("%d\n", uadd_ok(UINT_MAX, 1));
    printf("%d\n", uadd_ok(UINT_MAX - 1, 1));
    printf("%d\n", uadd_ok(UINT_MAX, 2));
    printf("%d\n", uadd_ok(UINT_MAX, 0));
    printf("%d\n", uadd_ok(0, 0));
    printf("=========\n");
    /* 有符号加法是否溢出 */
    printf("%d\n", tadd_ok(INT_MAX, 1));
    printf("%d\n", tadd_ok(INT_MAX - 1, 1));
    printf("%d\n", tadd_ok(INT_MAX, 2));
    printf("%d\n", tadd_ok(INT_MAX, 0));
    printf("%d\n", tadd_ok(0, 0));
    printf("%d\n", tadd_ok(INT_MIN, -1));
}

int uadd_ok(unsigned x, unsigned y) {
    unsigned s = x + y;
    return s >= x;
}

int tadd_ok(int x, int y) {
    int s = x + y;
    if (x > 0 && y > 0) {
        return s > 0;
    } else if (x < 0 && y < 0) {
        return s < 0;
    }
    return 1;
}